package com.aiboleepro.config;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置内置servlet
 *
 * @author aiboleepro
 * @date 2018-08-29 下午11:39
 **/
@Configuration
public class ServletConfig {


    @Value("${druid-monitor.logSlowSql}")
    private String logSlowSql;
    @Value("${druid-monitor.loginUsername}")
    private String loginUsername;
    @Value("${druid-monitor.loginPassword}")
    private String loginPassword;

    @Bean
    public ServletRegistrationBean druidServlet() {
        ServletRegistrationBean<StatViewServlet> reg = new ServletRegistrationBean<>();
        reg.setServlet(new StatViewServlet());
        reg.addUrlMappings("/druid/*");
        reg.addInitParameter("loginUsername", loginUsername);
        reg.addInitParameter("loginPassword", loginPassword);
        reg.addInitParameter("logSlowSql", logSlowSql);
        return reg;
    }
}
